/*
Copyright (C) 2010 
Author		  Oliver Schenk
Contact		  Oliver.Schenk76@gmail.com

This program is free software; you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; 
if not, see <http://www.gnu.org/licenses/>.
*/

<%@ page language="java" import="java.util.*,java.text.*"%>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="javax.jdo.Query" %>
<%@ page import="SelfBookingSystem.PMF" %>
<%@ page import="SelfBookingSystem.Texts" %>

<%!
public int nullIntconv(String inv)
{   
	int conv=0;
		
	try{
		conv=Integer.parseInt(inv);
	}
	catch(Exception e)
	{}
	return conv;
}

%>
<%
ArrayList AL_Text = new ArrayList();
AL_Text.add("No Error"); 
//Get Texts
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Texts.class);
List<Texts> texts = (List<Texts>) pm.newQuery(query).execute();
for (Texts t : texts) {
	AL_Text.add(t.getText()); 
}
			


    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
    	//Variablen and Format declaration
		String ConnectionData = new String(); // "tabbertabdefault";
		String Applications = new String(); // "tabbertabdefault";
   		String UserTitle = new String();
		String UserTitleJSPFile = new String();
		String AddUser = new String();
		int Result;


		ConnectionData = "";
		Applications = "";
		if(request.getParameter("Tab") != null){
			if (request.getParameter("Tab").contains(ConnectionData)){
				ConnectionData = "tabbertabdefault";
			}
		}
		AddUser= "";
		if(request.getParameter("AddUser") != null){
			if (request.getParameter("AddUser").contains("true")){
				AddUser = "tabbertabdefault";
			}
		}
		Result=0;
		if(request.getParameter("Result") != null){
			Result = Integer.parseInt(request.getParameter("Result"));
		}
		
    
	//If Return Code 9999 --> Exception
	//--> Redirect to Common Error Page
	if(Result==9999){
%>

	<jsp:forward page="../Error.jsp">
       <jsp:param name="forwardedFrom" value="Admin/index.jsp"/>
   </jsp:forward>
		
<%}%>


<p>Hello, <%= user.getNickname() %>! (You can
<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
<html>
<head>
<title>Admin Gui for SelfBookingSystem</title>
<script src="/JavaScript/JavaScriptAdminMenu.js" type="text/javascript"></script>
<script src="/JavaScript/TabMenu.js" type="text/javascript"></script>
<script src="/jscolor/jscolor.js" type="text/javascript"></script>

<link rel="stylesheet" href="/CSS/TabMenu.css" TYPE="text/css" MEDIA="screen">


</head>
<body>
<%=AL_Text.get(Result)%>
<table>
<tr>
<td>
<div class="tabber">

     <div class="tabbertab" title="Applications">
		<jsp:include page="Applications.jsp" />
     </div>



<%if(request.getParameter("AppID") != null){
	Map<String, String> m = SelfBookingSystem.GetConfigurationValues.GetConfigurationValues(request.getParameter("AppID"));
	UserTitle = "Add User";
	UserTitleJSPFile = "UserInformation.jsp";
%>

     <div class="tabbertab <%=ConnectionData%>" tabbertabhide title="Connection Data">
		<jsp:include page="ConnectionData.jsp" />
     </div>

     <div class="tabbertab <%=AddUser%>"  title="<%=UserTitle%>">
		<jsp:include page="<%=UserTitleJSPFile%>" />
     </div>
    
     
<%}%>

</div>

</td>
</tr>
</table>




</body>
</html>

<%
    } else {
%>
<p>Hello!
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
to include your name with greetings you post.</p>
<%
    }

%>


